package com.fenghongzhang.day009;

import android.os.Bundle;
import android.widget.SimpleAdapter;
import android.widget.Spinner;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private Spinner spinner;
    private Spinner spinner2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        //1
        spinner2 = (Spinner) findViewById(R.id.spinner2);

        //数据源
        List<Map<String,Object>> list = new ArrayList<>();

        String[] strings = new String[]{"小米","华为","苹果","笔"};
        int[] imgId = new int[]{R.mipmap.ic_launcher,R.mipmap.ku,R.mipmap.se,R.mipmap.pencil};
        for (int i = 0; i < strings.length; i++) {
            Map<String,Object> map = new HashMap<>();
            map.put("tu",imgId[i]);
            map.put("title",strings[i]);
            map.put("title2",imgId[i]);
            list.add(map);
        }
        //3适配器
        /**
         * 1,上下文
         * 2,数据源
         * 3,布局
         * 4.key的数组
         * 5.布局中组件的id数组
         */
        SimpleAdapter simpleAdapter =
                new SimpleAdapter(this, list, R.layout.sp_layout, new String[]{"tu","title","title2"}, new int[]{R.id.img, R.id.name,R.id.img1});

        //4.设置适配器
        spinner2.setAdapter(simpleAdapter);

















//        //1
//        spinner = (Spinner) findViewById(R.id.spinner);
//
//        //2,数据源
//        List<String> list = new ArrayList<>();
//        list.add("上单");
//        list.add("打野");
//        list.add("射手");
//        list.add("法王");
//
//
//        //3,适配器
//        //单行文字的用array
//
//        /**
//         * 1,上下文
//         * 2,固定写法 android.R.layout.simple_list_item_1
//         * 3.数据源
//         */
//        ArrayAdapter arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);
//
//        //4
//        spinner.setAdapter(arrayAdapter);







    }



}
